package IOFlow.practice;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

//练习3
public class Therr {
    public static void main(String[] args) throws IOException {
        //题目:修改文件数据

        FileReader fr=new FileReader("C:\\Users\\35337\\Desktop\\Temporary\\File\\c.txt");
        StringBuilder sb=new StringBuilder();
        int ch;
        while ((ch= fr.read())!=-1){
            sb.append((char)ch);
        }

        fr.close();

        //排序
        Integer[] arr=Arrays.stream(sb.toString()
                .split("-"))
                .map(Integer::parseInt)
                .sorted()
                .toArray(Integer[]::new);

        //写出
        FileWriter fw=new FileWriter("C:\\Users\\35337\\Desktop\\Temporary\\File\\c.txt");
        String result=Arrays.toString(arr).replace(",","-");
        fw.write(result);
        fw.close();
    }
}
